//
//  CZChangePhoneViewController.m
//  nsj_iOS
//
//  Created by apple on 2017/1/11.
//  Copyright © 2017年 GCZ. All rights reserved.
//

#import "CZChangePhoneViewController.h"
#import "CZVerificationBtn.h"

@interface CZChangePhoneViewController () <UITextFieldDelegate>
@property (weak, nonatomic) IBOutlet UITextField *oldCodeTF;
@property (weak, nonatomic) IBOutlet UITextField *phoneNewTF;
@property (weak, nonatomic) IBOutlet UITextField *codeNewTF;
@property (weak, nonatomic) IBOutlet UIButton *confirmBtn;

@property (weak, nonatomic) IBOutlet CZVerificationBtn *oldCodeBtn;
@property (weak, nonatomic) IBOutlet CZVerificationBtn *codeNewBtn;

@end

@implementation CZChangePhoneViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"更改手机";
    self.view.backgroundColor = GLOBAL_BACKGROUND_COLOR;
    [(UIView*)[self.navigationController.navigationBar.subviews objectAtIndex:0] setAlpha:1.f];
    _oldCodeBtn.phoneNumber = [[NSUserDefaults standardUserDefaults] objectForKey:User_Phone];
    _codeNewBtn.phoneNumber = @"";
    _oldCodeBtn.delgate = self;
    _codeNewBtn.delgate = self;
    _phoneNewTF.delegate = self;
    // Do any additional setup after loading the view from its nib.
}
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    self.tabBarController.tabBar.hidden = YES;
    self.navigationController.navigationBar.alpha = 1;
    
    [(UIView*)[self.navigationController.navigationBar.subviews objectAtIndex:0] setAlpha:1.f];
}
- (void)textFieldDidEndEditing:(UITextField *)textField {
    _codeNewBtn.phoneNumber = textField.text;
}




- (IBAction)changeConfirm:(id)sender {
    NSString *urlString = [NSString stringWithFormat:@"%@/api/web/index.php/v1/user/update-phone",APP_HOST];
    if (_oldCodeTF.text.length < 2) {
        [SVProgressHUD showErrorWithStatus:@"请输入旧手机获取的验证码"];
        return;
    }
    if (_phoneNewTF.text.length != 11) {
        [SVProgressHUD showErrorWithStatus:@"请输入新的手机号"];
    }
    if (_codeNewTF.text.length < 2) {
        [SVProgressHUD showErrorWithStatus:@"请输入新手机获取的验证码"];
        return;
    }
    
    [GCZAFNetWorking POST:urlString params:@{@"token" : [[NSUserDefaults standardUserDefaults] objectForKey:User_Token], @"old_code" : _oldCodeTF.text, @"new_phone" : _phoneNewTF.text, @"new_code" : _codeNewTF.text} success:^(NSDictionary *response) {
        if ([response[@"code"] isEqualToString:@"200"]) {
            [SVProgressHUD showSuccessWithStatus:@"修改手机号成功"];
        }
    } failure:^(NSURLSessionDataTask *operation, NSError *error) {
    }];
}
- (void)dealloc {
    
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
